<template>
	<div class="sponsor-view-rd">
		<common-header title="发起项目"></common-header>
		<div class="banner">乐趣投发起项目登记表</div>
		<div class="tip">
        	*信息提交后，我们将在七个工作日内进行反馈
		</div>
		<div class="form">
			<group label-width="105px" label-margin-right="2em" label-align="left" >
				<popup-picker title="项目类型" :data="projectTypeArr" v-model="projectType" value-text-align="right" placeholder="请选择"></popup-picker>
				<x-input title="联系人" v-model="name" is-type="china-name" placeholder="请输入姓名" text-align="right"></x-input>
				<x-input title="联系电话" mask="999 9999 9999" v-model="mobile" :max="13" placeholder="请输入手机号码" is-type="china-mobile" text-align="right"></x-input>
				<x-input title="微信号(选填)" v-model="wx" text-align="right"></x-input>
				<x-input title='项目名称' :max="20" v-model="projectName" placeholder="限20字" text-align="right"></x-input>
				<x-input title='项目位置' v-model="projectAddress" placeholder="如：浙江-温州-龙湾区" text-align="right"></x-input>
				<popup-picker title="项目进展" :data="projectStatusArr" v-model="projectStatus" value-text-align="right" placeholder="请选择"></popup-picker>
				<popup-picker title="物业权属" :data="projectOwnerArr" v-model="projectOwner" value-text-align="right" placeholder="请选择"></popup-picker>
				<x-input title='建筑面积' v-model="projectArea" placeholder="平方米" text-align="right"></x-input>
				<x-input title='房间数/门店数' v-model="projectRoomNum" placeholder="个" text-align="right"></x-input>
				<x-input title='客单价' v-model="projectPerMoney" placeholder="元/平均" text-align="right"></x-input>
				<x-textarea title="管理团队(选填)" v-model="teamIntro" placeholder="请介绍主要成员的姓名、年龄、职位及从业经验" ></x-textarea>
				<x-input title='拟总投金额' v-model="projectTotalMoney" placeholder="万元" text-align="right"></x-input>
				<x-input title='拟众筹金额' v-model="projectZcMoney" placeholder="万元" text-align="right"></x-input>
				<x-textarea title="备注(选填)" v-model="remark" placeholder="您是否还有其他补充说明或对我们的期望" ></x-textarea>
		    </group>
			<div class="submit-form">
				<x-button type="primary" @click.native="subPJ">提交</x-button>
			</div> 
		</div>
	</div>
</template>
<style>
	.sponsor-view-rd .weui-cells{margin-top:0;}
</style>
<style scoped lang="scss">
	.form *{font-size: 14px;}
	.submit-form{padding: 40px 15px 15px;}

	.weui-btn_primary {
		&:after{border:none;}
		font-size: 18px;
	    background-color: #0f2dcd;
		background: linear-gradient(left top,rgb(0,255,0),rgb(2,213,96));
		background-image: -webkit-linear-gradient( 0deg, rgb(0,255,0) 0%, rgb(2,213,96) 100%);
	}
	.tip{
		color: #666;
		font-size: 12px;
		padding: 20px 40px;
		background: #ffffff;
	}
	.banner{
		width: 100%;
		height: 180px;
		line-height: 180px;
		background-image: url(../../static/images/sponer.png);
		background-size: 100% 100%;
		background-position: center center;
		color: #ffffff;
		font-size: 22px;
		font-weight: bold;
		text-align: center;
	}
</style>

<script>
	import { GroupTitle, Group, Cell, XInput, Selector, PopupPicker, Datetime, XNumber, ChinaAddressData, XAddress, XTextarea } from 'vux'
	import commonHeader from '__cp/commonHeader';
	import {getCateList,postSponsor} from '__api';
	export default{
		name: 'sponsor-view',
		components:{
			Group,
			GroupTitle,
			Cell,
			XInput,
			Selector,
			PopupPicker,
			XAddress,
			Datetime,
			XNumber,
			XTextarea,
			commonHeader
		},
		data(){
			return{
				count:60,
				postStatus:true,
				cateArr:[],
				projectType:[],
				name: '',
				mobile: '',
				wx:'',
				projectName:'',
				projectAddress:'',
				projectStatus:[],
				projectOwner:[],
				projectArea:'',
				projectRoomNum:'',
				projectPerMoney:'',
				teamIntro:'',
				projectTotalMoney:'',
				projectZcMoney:'',
				remark:'',
				projectStatusArr:[['未施工','施工中','待营业','营业中']],
				projectOwnerArr:[['租赁','自持','其他']],
				projectTypeArr:[
				],
			}
		},
		mounted(){
			this.$nextTick(()=>{
				this.getPJType();
			})
		},
		methods:{
			getPJType(){
				getCateList().then(res=>{
					let arr = [];
					this.cateArr = res.cate_result;
					res.cate_result.forEach((v)=>{
						arr.push(v.name)
					})
					this.projectTypeArr.push(arr);
				})
			},
			subPJ(){
				if(!this.postStatus){
					this.$vux.toast.text('提交频繁，请'+this.count+'秒后再试','top');
					return;
				}
				this.$loading();
				let ci = '';
				this.cateArr.forEach((v)=>{
					if(v.name == this.projectType[0]){
						ci = v.id
					}
				})

				postSponsor({
					cate_id: ci,
					linkman: this.name,
					linkphone: this.mobile,
					linkweixin: this.wx,
					name:this.projectName,
					address:this.projectAddress,
					projectprogress:this.projectStatus[0],
					belongto:this.projectOwner[0],
					area: this.projectArea,
					stores: this.projectRoomNum,
					storeprice: this.projectPerMoney,
					manages: this.teamIntro,
					totalinvest: this.projectTotalMoney,
					limit_price: this.projectZcMoney,
					remark: this.remark,
					type: 99
				}).then(res=>{
					if(res.status == 1){
						this.$vux.toast.text('提交成功','top')
						let timer = setInterval(()=>{
							this.count--;
							if(this.count <= 0){
								clearInterval(timer);
								this.count = 60;
								this.postStatus = true;
							}
						},1000)
						this.postStatus = false;
					} else {
						this.$vux.toast.text(res.msg ? res.msg : '网络超时','top')
					}
					this.$loading.end();
				})
			}
		}
	};

</script>